package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.SignInHistory;
import cn.wolfcode.trip.base.service.ISignInHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 签到控制器
 */
@RestController
@RequestMapping("signInHistorys")
public class SignInHistoryController {
    @Autowired
    private ISignInHistoryService signInHistoryService;

    /**
     * 根据用户id,和当天日期,获取签到对象的接口
     * 1.资源 /signInHistorys/{userId}
     * 2.请求方式 get
     * 3.请求参数 无
     * 4.返回结果 signInHistorys
     */
    //获取当前用户的所有签到信息
    @GetMapping("{userId}")
    public List<SignInHistory> getByIdAndDate(@PathVariable Long userId) {

        return signInHistoryService.queryByUserId(userId);
    }

    //获取当前用户签到的本月签到天数集合
    @GetMapping("{userId}/days")
    public List<Integer> getSignInDays(@PathVariable Long userId,String month) throws ParseException {


        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date date = new Date();
        String strMonth = sdf.format(date);
        if(month!=null&&month.equals("2019-05")){
            strMonth=month;
        }

        return signInHistoryService.queryDaysByMonth(strMonth,userId);
    }
}
